<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<c:set var="contestPath" value="<%=request.getContextPath()%>"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.testDescription {
    margin: 20px 0 0;
    padding: 10px 20px;
    background-color: #feffd1;
    font-size: 15px;
    color: #666;
}
.testDescription span{
	font-weight: 700;
}

</style>
<script type="text/javascript">
	$(function(){
		function initTimer(){
			var resultTime = 0;
			var testTotalTime = Number('${sub.totalTime}');
			return testTotalTime * 60;
		}
		function statrtTimer(totalSecend){
			$('#testTimer').text(formatTime(totalSecend));
			var timer = setInterval(function(){
				totalSecend --;
				if(totalSecend >= 0){
					$('#testTimer').text(formatTime(totalSecend));
				}else{
					alert('考试结束!');
					clearInterval(timer);
					assignment();
				}
			}, 1000);
		}
		function formatTime(totalSecend){
			var hour = Math.floor(totalSecend / 3600);
			var min = Math.floor((totalSecend % 3600) / 60);
			var secend = Math.floor(totalSecend % 60);
			hour = formatTimeNumber(hour);
			min = formatTimeNumber(min);
			secend = formatTimeNumber(secend);
			return hour + ':' + min + ':' + secend;
		}

		function formatTimeNumber(timeNumber){
			if(timeNumber < 10){
				return "0" + timeNumber;
			} else {
				return timeNumber;
			}
		}

		function assignment(){
			$('#test-form').submit();
		}
		
		$('#submitTestBtn').click(function(){
			if(confirm("是否确认提交？")){
				assignment();
			}
		});
		statrtTimer(initTimer());
	})
	
</script>

</head>
<body>
<!-- /section:settings.box -->
		<div class="page-content-area">
			<div class="page-header">
			<div class="testDescription">
			本次考试的参考时长为:&nbsp;&nbsp;<span id="testTimer"></span>&nbsp;&nbsp;&nbsp;&nbsp;总分为:&nbsp;&nbsp;<span id="testScore">${sub.totalScore }</span>&nbsp;&nbsp;分
			</div>
			</div><!-- /.page-header -->

			<div class="row">
				<div class="col-xs-12">
					<!-- PAGE CONTENT BEGINS -->
					<div class="row">
					<form id="test-form" action="${contestPath}/student/assignment" method="post">
						<input type="hidden" name="userId" value="${examUser.userId }" />
						<input type="hidden" name="subId" value="${sub.subId }" />
						<% int i = 1; %>
						<c:forEach items="${testListMap[1] }" var="radio">
		            	<label><%=i %>、</label><span class="content">${radio.content }</span>(<span class="test-type">${radio.examTestType.testType }</span>,<span class="test-type-score">${radio.examTestType.testTypeScore }</span>分)<br />
		            	<label><input type="radio" name="test_${radio.id }" value="A"/>&nbsp;&nbsp;A、</label><span class="choose-a">${radio.chooseA }</span><br />
		            	<label><input type="radio" name="test_${radio.id }" value="B"/>&nbsp;&nbsp;B、</label><span class="choose-b">${radio.chooseB }</span><br />
		            	<label><input type="radio" name="test_${radio.id }" value="C"/>&nbsp;&nbsp;C、</label><span class="choose-c">${radio.chooseC }</span><br />
		            	<label><input type="radio" name="test_${radio.id }" value="D"/>&nbsp;&nbsp;D、</label><span class="choose-d">${radio.chooseD }</span><br />
		            	<% i++; %>
						</c:forEach>
						<c:forEach items="${testListMap[2] }" var="radio">
		            	<label><%=i %>、</label><span class="content">${radio.content }</span>(<span class="test-type">${radio.examTestType.testType }</span>,<span class="test-type-score">${radio.examTestType.testTypeScore }</span>分)<br />
		            	<label><input type="checkbox" name="test_${radio.id }" value="A">&nbsp;&nbsp;A、</label><span class="choose-a">${radio.chooseA }</span><br />
		            	<label><input type="checkbox" name="test_${radio.id }" value="B">&nbsp;&nbsp;B、</label><span class="choose-b">${radio.chooseB }</span><br />
		            	<label><input type="checkbox" name="test_${radio.id }" value="C">&nbsp;&nbsp;C、</label><span class="choose-c">${radio.chooseC }</span><br />
		            	<label><input type="checkbox" name="test_${radio.id }" value="D">&nbsp;&nbsp;D、</label><span class="choose-d">${radio.chooseD }</span><br />
		            	<% i++; %>
						</c:forEach>
					</form>
					</div><!-- /.row -->
					<button id="submitTestBtn" type="button" class="btn btn-primary">提交</button>
					<div class="hr hr-18 dotted hr-double"></div>
				</div><!-- /.col -->
			</div><!-- /.row -->
		</div><!-- /.page-content-area -->
</body>
</html>